package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseTeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;
import com.itheima.edu.info.manager.factory.TeacherDaoFactory;

public class TeacherService {
    private BaseTeacherDao teacherDao = TeacherDaoFactory.getTeacherDao();

    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public Teacher[] findAllTeacher() {

        return teacherDao.findAllTeacher();
    }

    public boolean isExists(String sid) {
        Teacher[] allTeacher = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            if (allTeacher[i] != null && sid.equals(allTeacher[i].getSid())) {
                flag = true;
            }
        }
        return flag;
    }


    public void updateTeacher(String sid, Teacher teacher) {
         teacherDao.updateTeacher(sid, teacher);
    }

    public void deleteTeacher(String sid) {
         teacherDao.deleteTeacher(sid);
    }
}
